﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SGP;
using System.IO;
using System.Xml.Linq;

namespace Particle_Editor
{
    public partial class Form1 : Form
    {
        private bool looping;
        private ManagedDirect3D D3D = null;
        private ManagedTextureManager TextureManager = null;
        private Emitter emitter = new Emitter();
        private Color previewColor = new Color();
        private Color startingColor = new Color();
        private Color endingColor = new Color();
        private bool loaded1 = false;
        private bool loaded2 = false;
        private bool clicked = false;
        private string FilePath = "";
        private string FileName = "";
        private string SaveImage = "";

        public bool Looping
        {
            get { return looping; }
            set { looping = value; }
        }

        public Form1()
        {
            InitializeComponent();
            InitEverything();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            looping = false;
        }

        public bool OpenFilePath()
        {
            FolderBrowserDialog FBD = new FolderBrowserDialog();

            if (DialogResult.OK == FBD.ShowDialog())
            {
                FilePath = FBD.SelectedPath;

                return true;
            }
            else
                return false;
        }

        private void InitEverything()
        {
            D3D = ManagedDirect3D.Instance;
            TextureManager = ManagedTextureManager.Instance;
            D3D.InitManagedDirect3D(panel1);
            D3D.InitManagedDirect3D(panel2);
            D3D.InitManagedDirect3D(panel3);
            D3D.InitManagedDirect3D(panel4);
            TextureManager.InitManagedTextureManager(D3D.Device, D3D.Sprite);
            previewColor = Color.Black;
            startingColor = Color.White;
            endingColor = Color.White;
        }

        public void Render()
        {
            D3D.ChangeDisplayParam(panel2);
            D3D.Clear(previewColor);
            D3D.Present();
            D3D.ChangeDisplayParam(panel3);
            D3D.Clear(emitter.StartColor);
            D3D.Present();
            D3D.ChangeDisplayParam(panel4);
            D3D.Clear(emitter.EndColor);
            D3D.Present();
            D3D.ChangeDisplayParam(panel1);
            D3D.Clear(previewColor);

            D3D.DeviceBegin();
            D3D.SpriteBegin();

            emitter.Render();
            
            D3D.SpriteEnd();
            D3D.DeviceEnd();
            D3D.Present();
        }

        public void Update1()
        {
            emitter.Update(1.0f);
        }

        private void loadToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenFileDialog Dlg = new OpenFileDialog();
            Dlg.Filter = "All Files|*.*|Xml Files|*.xml";
            Dlg.FilterIndex = 2;

            if (DialogResult.OK == Dlg.ShowDialog())
            {
                XElement Root = XElement.Load(Dlg.FileName);

                //Life
                XElement Life = Root.Element("Life");
                XAttribute MinLife = Life.Attribute("MinLife");
                XAttribute MaxLife = Life.Attribute("MaxLife");

                //Color
                XElement color = Root.Element("Color");
                XAttribute StartColorR = color.Attribute("StartColor.r");
                XAttribute StartColorG = color.Attribute("StartColor.g");
                XAttribute StartColorB = color.Attribute("StartColor.b");
                XAttribute StartColorA = color.Attribute("StartColor.a");
                XAttribute EndColorR = color.Attribute("EndColor.r");
                XAttribute EndColorG = color.Attribute("EndColor.g");
                XAttribute EndColorB = color.Attribute("EndColor.b");
                XAttribute EndColorA = color.Attribute("EndColor.a");

                //Velocity
                XElement velocity = Root.Element("Velocity");
                XAttribute VelX = velocity.Attribute("VelocityX");
                XAttribute VelY = velocity.Attribute("VelocityY");
                XAttribute EndVelX = velocity.Attribute("EndVelocityX");
                XAttribute EndVelY = velocity.Attribute("EndVelocityY");

                //Rect
                XElement Rect = Root.Element("Rect");
                XAttribute Left = Rect.Attribute("Left");
                XAttribute Top = Rect.Attribute("Top");
                XAttribute Right = Rect.Attribute("Right");
                XAttribute Bottom = Rect.Attribute("Bottom");

                //Scale
                XElement scale = Root.Element("Scale");
                XAttribute scaleX = scale.Attribute("ScaleX");
                XAttribute scaleY = scale.Attribute("ScaleY");
                XAttribute EndscaleX = scale.Attribute("EndScaleX");
                XAttribute EndscaleY = scale.Attribute("EndScaleY");

                //loop
                XElement loop = Root.Element("Loop");
                XAttribute islooping = loop.Attribute("Looping");

                //Blend
                XElement Blend = Root.Element("Blend");
                XAttribute SrcBlend = Blend.Attribute("SourceBlend");
                XAttribute DstBlend = Blend.Attribute("DestBlend");

                //Image 
                XElement Image = Root.Element("Image");
                XAttribute imageId = Image.Attribute("ImageID");

                //MaxParticles
                XElement maxParticles = Root.Element("MaxParticles");
                XAttribute maxParts = maxParticles.Attribute("MaxParticles");


                float minlife = float.Parse(MinLife.Value);
                float maxlife = float.Parse(MaxLife.Value);
                int SCA = int.Parse(StartColorA.Value);
                int SCR = int.Parse(StartColorR.Value);
                int SCG = int.Parse(StartColorG.Value);
                int SCB = int.Parse(StartColorB.Value);
                int ECA = int.Parse(EndColorA.Value);
                int ECR = int.Parse(EndColorR.Value);
                int ECG = int.Parse(EndColorG.Value);
                int ECB = int.Parse(EndColorB.Value);
                Color startColor = Color.FromArgb(SCA, SCR, SCG, SCB);
                Color endColor = Color.FromArgb(ECA, ECR, ECG, ECB);
                float velx = float.Parse(VelX.Value);
                float vely = float.Parse(VelY.Value);
                int left = int.Parse(Left.Value);
                int top = int.Parse(Top.Value);
                int right = int.Parse(Right.Value);
                int bottom = int.Parse(Bottom.Value);
                Rectangle RECT = new Rectangle(left, top, (right - left), (bottom - top));
                float ScaleX = float.Parse(scaleX.Value);
                float ScaleY = float.Parse(scaleY.Value);
                int INTloops = int.Parse(islooping.Value);
                float EscaleX = float.Parse(EndscaleX.Value);
                float EscaleY = float.Parse(EndscaleY.Value);
                float EVelX = float.Parse(EndVelX.Value);
                float EVelY = float.Parse(EndVelY.Value);

                bool Looper = false;
                if (INTloops == 0)
                    Looper = false;
                else
                    Looper = true;

                int sourceBld = int.Parse(SrcBlend.Value);
                int destBld = int.Parse(DstBlend.Value);
                float MP = float.Parse(maxParts.Value);

                FileName = imageId.Value; 

                string theImage = FilePath + "\\" + FileName;

                int ID = TextureManager.LoadTexture(theImage, 0);

                emitter = new Emitter(RECT, ID, sourceBld, destBld, minlife, maxlife,
                                      Looper, startColor, endColor, MP, ScaleX, ScaleY, velx, vely,
                                      0.0f, EscaleX, EscaleY, EVelX, EVelY);

                numericUpDown4.Value = (decimal)emitter.VelX;
                numericUpDown3.Value = (decimal)emitter.VelY;
                numericUpDown5.Value = (decimal)emitter.ScaleY;
                numericUpDown6.Value = (decimal)emitter.ScaleX;
                numericUpDown1.Value = (decimal)emitter.EndVelX;
                numericUpDown2.Value = (decimal)emitter.EndVelY ;
                numericUpDown7.Value = (decimal)emitter.EndScaleX;
                numericUpDown8.Value = (decimal)emitter.EndScaleY;
                numericUpDown11.Value = (decimal)emitter.MaxLife;
                numericUpDown14.Value = (decimal)emitter.EmitterRect.Left;
                numericUpDown16.Value = (decimal)emitter.EmitterRect.Top;
                numericUpDown10.Value = (decimal)emitter.EmitterRect.Height;
                numericUpDown9.Value = (decimal)emitter.EmitterRect.Width;
                numericUpDown18.Value = (decimal)emitter.MaxParticles;
                numericUpDown17.Value = (decimal)emitter.Rotation;
                loaded1 = true;
                loaded2 = true;
                comboBox2.SelectedIndex = emitter.SourceBlend;
                comboBox1.SelectedIndex = emitter.DestBlend;
                checkBox1.CheckState = CheckState.Checked;
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (loaded1 == false)
                emitter.SourceBlend = comboBox2.Items.IndexOf(comboBox2.SelectedItem) + 1;
            else
                loaded1 = false;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (loaded2 == false)
                emitter.DestBlend = comboBox1.Items.IndexOf(comboBox1.SelectedItem) + 1;
            else
                loaded2 = false;
        }

        private void numericUpDown18_ValueChanged(object sender, EventArgs e)
        {
            emitter.MaxParticles = (float)numericUpDown18.Value;
            emitter.SetParticles(emitter.MaxParticles);
        }


        private void numericUpDown11_ValueChanged(object sender, EventArgs e)
        {
            emitter.MaxLife = (float)numericUpDown11.Value;
        }

        private void numericUpDown14_ValueChanged(object sender, EventArgs e)
        {
            emitter.EmitterRect = new Rectangle((int)numericUpDown14.Value, emitter.EmitterRect.Top,
                                                emitter.EmitterRect.Width, emitter.EmitterRect.Height);
        }

        private void numericUpDown16_ValueChanged(object sender, EventArgs e)
        {
            emitter.EmitterRect = new Rectangle(emitter.EmitterRect.Left, (int)numericUpDown16.Value,
                                                emitter.EmitterRect.Width, emitter.EmitterRect.Height);
        }

        private void numericUpDown9_ValueChanged(object sender, EventArgs e)
        {
            emitter.EmitterRect = new Rectangle(emitter.EmitterRect.Left, emitter.EmitterRect.Top,
                                                (int)numericUpDown9.Value, emitter.EmitterRect.Height);
        }

        private void numericUpDown10_ValueChanged(object sender, EventArgs e)
        {
            emitter.EmitterRect = new Rectangle(emitter.EmitterRect.Left, emitter.EmitterRect.Top,
                                                emitter.EmitterRect.Width, (int)numericUpDown10.Value);
        }

        private void numericUpDown4_ValueChanged(object sender, EventArgs e)
        {
            emitter.VelX = (int)numericUpDown4.Value;
        }

        private void numericUpDown3_ValueChanged(object sender, EventArgs e)
        {
            emitter.VelY = (int)numericUpDown3.Value;
        }

        private void numericUpDown6_ValueChanged(object sender, EventArgs e)
        {
            emitter.ScaleX = (float)numericUpDown6.Value;
        }

        private void numericUpDown5_ValueChanged(object sender, EventArgs e)
        {
            emitter.ScaleY = (float)numericUpDown5.Value;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
                emitter.looping = true;
            else
                emitter.looping = false;
                
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ColorDialog cDlg = new ColorDialog();

            cDlg.ShowDialog();

            previewColor = cDlg.Color;

            D3D.ChangeDisplayParam(panel2);
            D3D.Clear(previewColor);
            D3D.Present();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ColorDialog cDlg = new ColorDialog();

            cDlg.ShowDialog();

            startingColor = cDlg.Color;

            D3D.ChangeDisplayParam(panel3);
            D3D.Clear(startingColor);
            D3D.Present();

            emitter.StartColor = startingColor;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ColorDialog cDlg = new ColorDialog();

            cDlg.ShowDialog();

            endingColor = cDlg.Color;

            D3D.ChangeDisplayParam(panel4);
            D3D.Clear(endingColor);
            D3D.Present();

            emitter.EndColor = endingColor;
        }

        private void numericUpDown17_ValueChanged(object sender, EventArgs e)
        {
            emitter.Rotation = (float)numericUpDown17.Value;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Random rand = new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0));

            if (checkBox3.Checked)
            {
                emitter.VelX = rand.Next((int)numericUpDown4.Minimum, (int)numericUpDown4.Maximum);
                emitter.VelY = rand.Next((int)numericUpDown3.Minimum, (int)numericUpDown3.Maximum);

                numericUpDown4.Value = (decimal)emitter.VelX;
                numericUpDown3.Value = (decimal)emitter.VelY;
            }

            if (checkBox4.Checked)
            {
                emitter.ScaleX = rand.Next((int)numericUpDown6.Minimum, (int)numericUpDown6.Maximum);
                emitter.ScaleY = rand.Next((int)numericUpDown5.Minimum, (int)numericUpDown5.Maximum);

                numericUpDown6.Value = (decimal)emitter.ScaleX;
                numericUpDown5.Value = (decimal)emitter.ScaleY;
            }


            if (checkBox6.Checked)
            {
                emitter.MaxLife = rand.Next((int)numericUpDown11.Minimum, (int)numericUpDown11.Maximum);

                numericUpDown11.Value = (decimal)emitter.MaxLife;
            }

            if (checkBox7.Checked)
            {
                int RandLeft = rand.Next((int)numericUpDown14.Minimum, (int)numericUpDown14.Maximum);
                int Randtop = rand.Next((int)numericUpDown16.Minimum, (int)numericUpDown16.Maximum);

                emitter.EmitterRect = new Rectangle(RandLeft, Randtop, emitter.EmitterRect.Width,
                                                    emitter.EmitterRect.Height);

                numericUpDown14.Value = RandLeft;
                numericUpDown16.Value = Randtop;
            }

            if (checkBox12.Checked)
            {
                emitter.Rotation = rand.Next((int)numericUpDown17.Minimum, (int)numericUpDown17.Maximum);

                numericUpDown17.Value = (decimal)emitter.Rotation;
            }

            if (checkBox10.Checked)
            {
                int RandWidth = rand.Next((int)numericUpDown9.Minimum, (int)numericUpDown9.Maximum);

                emitter.EmitterRect = new Rectangle(emitter.EmitterRect.Left, emitter.EmitterRect.Top,
                                                    RandWidth, emitter.EmitterRect.Height);

                numericUpDown9.Value = RandWidth;
            }

            if (checkBox11.Checked)
            {
                int RandHeight = rand.Next((int)numericUpDown10.Minimum, (int)numericUpDown10.Maximum);

                emitter.EmitterRect = new Rectangle(emitter.EmitterRect.Left, emitter.EmitterRect.Top,
                                                    emitter.EmitterRect.Width, RandHeight);

                numericUpDown10.Value = RandHeight;
            }

            if (checkBox13.Checked)
            {
                comboBox2.SelectedIndex = rand.Next(0, comboBox2.MaxDropDownItems);

                emitter.SourceBlend = comboBox2.SelectedIndex + 1;
            }

            if (checkBox14.Checked)
            {
                comboBox1.SelectedIndex = rand.Next(0, comboBox1.MaxDropDownItems);

                emitter.DestBlend = comboBox1.SelectedIndex + 1;
            }

            if (checkBox15.Checked)
            {
                emitter.StartColor = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
            }

            if (checkBox16.Checked)
            {
                emitter.EndColor = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
            }

            if (checkBox17.Checked)
            {
                previewColor = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
            }

            if (checkBox2.Checked)
            {
                emitter.MaxParticles = rand.Next((int)numericUpDown18.Minimum, (int)numericUpDown18.Maximum);
                emitter.SetParticles(emitter.MaxParticles);

                numericUpDown18.Value = (decimal)emitter.MaxParticles;
            }
        }

        private void checkALLToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            checkBox2.CheckState = CheckState.Checked;
            checkBox3.CheckState = CheckState.Checked;
            checkBox4.CheckState = CheckState.Checked;
            checkBox6.CheckState = CheckState.Checked;
            checkBox7.CheckState = CheckState.Checked;
            checkBox10.CheckState = CheckState.Checked;
            checkBox11.CheckState = CheckState.Checked;
            checkBox12.CheckState = CheckState.Checked;
            checkBox13.CheckState = CheckState.Checked;
            checkBox14.CheckState = CheckState.Checked;
            checkBox15.CheckState = CheckState.Checked;
            checkBox16.CheckState = CheckState.Checked;
            checkBox17.CheckState = CheckState.Checked;
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                clicked = true;
            }
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (clicked == true)
            {
                emitter.EmitterRect = new Rectangle(e.X, 
                    e.Y, emitter.EmitterRect.Width, emitter.EmitterRect.Height);


                if (e.X >= panel1.Width || e.X >= numericUpDown14.Maximum)
                {
                    numericUpDown14.Maximum = panel1.Width;
                    numericUpDown14.Value = numericUpDown14.Maximum;
                }
                else
                    numericUpDown14.Value = e.X;



                if (e.Y >= panel1.Height || e.Y >= numericUpDown16.Maximum)
                {
                    numericUpDown16.Maximum = panel1.Height;
                    numericUpDown16.Value = numericUpDown16.Maximum;
                }
                else
                    numericUpDown16.Value = e.Y;
            }
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                clicked = false;
            }
        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog SFD = new SaveFileDialog();
            SFD.Filter = "All Files|*.*|Xml Files|*.xml";
            SFD.FilterIndex = 2;
            SFD.DefaultExt = "xml";

            if (DialogResult.OK == SFD.ShowDialog())
            {
                //Root
                XElement Root = new XElement("Emitter");

                //Life element
                XElement Life = new XElement("Life");
                Root.Add(Life);

                XAttribute MinLife = new XAttribute("MinLife", emitter.MinLife);
                Life.Add(MinLife);

                XAttribute MaxLife = new XAttribute("MaxLife", emitter.MaxLife);
                Life.Add(MaxLife);

                //Color Element
                XElement color = new XElement("Color");
                Root.Add(color);

                XAttribute red = new XAttribute("StartColor.r", emitter.StartColor.R);
                color.Add(red);

                XAttribute green = new XAttribute("StartColor.g", emitter.StartColor.G);
                color.Add(green);

                XAttribute blue = new XAttribute("StartColor.b", emitter.StartColor.B);
                color.Add(blue);

                XAttribute alpha = new XAttribute("StartColor.a", emitter.StartColor.A);
                color.Add(alpha);

                XAttribute endRed = new XAttribute("EndColor.r", emitter.EndColor.R);
                color.Add(endRed);

                XAttribute endGreen = new XAttribute("EndColor.g", emitter.EndColor.G);
                color.Add(endGreen);

                XAttribute endBlue = new XAttribute("EndColor.b", emitter.EndColor.B);
                color.Add(endBlue);

                XAttribute endAlpha = new XAttribute("EndColor.a", emitter.EndColor.A);
                color.Add(endAlpha);

                //Velocity Element
                XElement Velocity = new XElement("Velocity");
                Root.Add(Velocity);

                XAttribute VelX = new XAttribute("VelocityX", emitter.VelX);
                Velocity.Add(VelX);

                XAttribute VelY = new XAttribute("VelocityY", emitter.VelY);
                Velocity.Add(VelY);

                XAttribute VelXEnd = new XAttribute("EndVelocityX", emitter.EndVelX);
                Velocity.Add(VelXEnd);

                XAttribute VelYEnd = new XAttribute("EndVelocityY", emitter.EndVelY);
                Velocity.Add(VelYEnd);

                //Rect Element
                XElement Rect = new XElement("Rect");
                Root.Add(Rect);

                XAttribute RectLeft = new XAttribute("Left", emitter.EmitterRect.Left);
                Rect.Add(RectLeft);

                XAttribute RectTop = new XAttribute("Top", emitter.EmitterRect.Top);
                Rect.Add(RectTop);

                XAttribute RectRight = new XAttribute("Right", emitter.EmitterRect.Right);
                Rect.Add(RectRight);

                XAttribute RectBottom = new XAttribute("Bottom", emitter.EmitterRect.Bottom);
                Rect.Add(RectBottom);

                //Scale Element
                XElement Scale = new XElement("Scale");
                Root.Add(Scale);

                XAttribute ScaleX = new XAttribute("ScaleX", emitter.ScaleX);
                Scale.Add(ScaleX);

                XAttribute ScaleY = new XAttribute("ScaleY", emitter.ScaleY);
                Scale.Add(ScaleY);

                XAttribute ScaleXEnd = new XAttribute("EndScaleX", emitter.EndScaleX);
                Scale.Add(ScaleXEnd);

                XAttribute ScaleYEnd = new XAttribute("EndScaleY", emitter.EndScaleY);
                Scale.Add(ScaleYEnd);

                //Loop Element
                XElement Loop = new XElement("Loop");
                Root.Add(Loop);

                int loopInt = 0;

                if (emitter.looping == true)
                    loopInt = 1;
                else
                    loopInt = 0;

                XAttribute isLooping = new XAttribute("Looping", loopInt);
                Loop.Add(isLooping);

                //Blend Element
                XElement Blend = new XElement("Blend");
                Root.Add(Blend);

                XAttribute SourceBlend = new XAttribute("SourceBlend", emitter.SourceBlend);
                Blend.Add(SourceBlend);

                XAttribute DestBlend = new XAttribute("DestBlend", emitter.DestBlend);
                Blend.Add(DestBlend);

                //Image Element
                XElement Image = new XElement("Image");
                Root.Add(Image);

                XAttribute ImageID = new XAttribute("ImageID", FileName);
                Image.Add(ImageID);

                //MaxParticle Element
                XElement MaxParticles = new XElement("MaxParticles");
                Root.Add(MaxParticles);

                XAttribute maxParticles = new XAttribute("MaxParticles", emitter.MaxParticles);
                MaxParticles.Add(maxParticles);

                Root.Save(SFD.FileName);
            }
        }

        private void importImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog Dlg = new OpenFileDialog();

            if (DialogResult.OK == Dlg.ShowDialog())
            {
                FileName = Dlg.SafeFileName;

                string fullpath = FilePath + "\\" + FileName;

                int ID = TextureManager.LoadTexture(fullpath, 0);

                Rectangle rect = new Rectangle(0, 0, 100, 100);

                emitter = new Emitter(rect, ID, 2, 2, 0, 50, true, Color.White, Color.White, 50, 
                                      1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f);

                numericUpDown4.Value = (decimal)emitter.VelX;
                numericUpDown3.Value = (decimal)emitter.VelY;
                numericUpDown5.Value = (decimal)emitter.ScaleY;
                numericUpDown6.Value = (decimal)emitter.ScaleX;
                numericUpDown11.Value = (decimal)emitter.MaxLife;
                numericUpDown14.Value = (decimal)emitter.EmitterRect.Left;
                numericUpDown16.Value = (decimal)emitter.EmitterRect.Top;
                numericUpDown10.Value = (decimal)emitter.EmitterRect.Height;
                numericUpDown9.Value = (decimal)emitter.EmitterRect.Width;
                numericUpDown18.Value = (decimal)emitter.MaxParticles;
                numericUpDown17.Value = (decimal)emitter.Rotation;
                numericUpDown1.Value = (decimal)emitter.EndVelX;
                numericUpDown2.Value = (decimal)emitter.EndVelY;
                numericUpDown7.Value = (decimal)emitter.EndScaleX;
                numericUpDown8.Value = (decimal)emitter.EndScaleY;
                loaded1 = true;
                loaded2 = true;
                comboBox2.SelectedIndex = emitter.SourceBlend;
                comboBox1.SelectedIndex = emitter.DestBlend;
                checkBox1.CheckState = CheckState.Checked;
            }
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            emitter.EndVelX = (float)numericUpDown1.Value;
        }

        private void numericUpDown2_ValueChanged(object sender, EventArgs e)
        {
            emitter.EndVelY = (float)numericUpDown2.Value;
        }

        private void numericUpDown7_ValueChanged(object sender, EventArgs e)
        {
            emitter.EndScaleX = (float)numericUpDown7.Value;
        }

        private void numericUpDown8_ValueChanged(object sender, EventArgs e)
        {
            emitter.EndScaleY = (float)numericUpDown8.Value;
        }
    }
}
